﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Threading;
using System.Globalization;
using Nivdal.AuxCode;

namespace Nivdal
{
    public partial class InternalTeamMessageDetails : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = Resources.Resource.Default_PageTitle + ", " + Resources.Resource.InternalTeamMessageDetails_PageTitle;
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
                Response.Redirect("~/Default.aspx");
            OnlineUser ou = (OnlineUser)Session["User"];
            if (ou.TeamId == "Null")
                Response.Redirect("~/GeneralMessage.aspx?MessageString=M74ggdizz5wfeh");

            string MessageId = null;
            if (!IsPostBack)
            {
                if (Request.QueryString["MessageId"] != null)
                {
                    MessageId = Request.QueryString["MessageId"].ToString();
                    MessageIdHiddenField.Value = MessageId;
                }
                else
                    Response.Redirect("~/TeamHomePage.aspx");
            
                GetMessageDetailsSqlDataSourse.SelectParameters.Add("MessageId", MessageId);
                GetMessageDetailsSqlDataSourse.SelectParameters.Add("UserId", ou.UserId);
            }

        }

        protected string ReturnButtonText(object ButtonType)
        {
            string ButtonText = ButtonType.ToString();
            string ReturnValue = ButtonText;

            switch (ButtonText)
            { 
                case "AcceptFriendly":
                    ReturnValue = Resources.Resource.Friends_AcceptLinkButtonText;
                    break;
                case "AcceptFriendship":
                    ReturnValue = Resources.Resource.Friends_AcceptLinkButtonText;
                    break;
                case "DeclineFriendly":
                    ReturnValue = Resources.Resource.Friends_DeclineLinkButtonText;
                    break;
                case "DeclineFriendship":
                    ReturnValue = Resources.Resource.Friends_DeclineLinkButtonText;
                    break;
                case "JoinForum":
                    ReturnValue = Resources.Resource.Friendly_JoinButtonText;
                    break;
            }
            return ReturnValue;
        }

        protected void ButtonsAction(object sender, FormViewCommandEventArgs e)
        {
            OnlineUser ou = (OnlineUser)Session["User"];
            GetNivdalData.GetNivdalData GND = new GetNivdalData.GetNivdalData();
            string Answer;
            switch (e.CommandName)
            { 
                case "AcceptFriendly":
                    Answer = GND.ReadNivdalStringData("ChallangeId", "Language", "Nivdal_FriendlyAcceptFriendlyChallange", e.CommandArgument, ou.Language);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/Friendly.aspx?Message=" + Answer);
                    break;
                case "AcceptNTFriendly":
                    Answer = GND.ReadNivdalStringData("ChallangeId", "Language", "Nivdal_FriendlyAcceptFriendlyChallange", e.CommandArgument, ou.Language);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/FriendlyNT.aspx?Message=" + Answer);
                    break;
                case "AcceptFriendship":
                    Answer = GND.ReadNivdalStringData("SuggestionId", "Nivdal_FriendshipApproveFriendshipSuggestion", e.CommandArgument);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/Friends.aspx?Message=" + Answer);
                    break;
                case "DeclineFriendly":
                    Answer = GND.ReadNivdalStringData("ChallangeId", "Language", "Nivdal_FriendlyDeclineFriendlyChalange", e.CommandArgument, ou.Language);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/Friendly.aspx?Message=" + Answer);
                    break;
                case "DeclineNTFriendly":
                    Answer = GND.ReadNivdalStringData("ChallangeId", "Language", "Nivdal_FriendlyDeclineFriendlyChalange", e.CommandArgument, ou.Language);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/FriendlyNT.aspx?Message=" + Answer);
                    break;
                case "DeclineFriendship":
                    Answer = GND.ReadNivdalStringData("SuggestionId", "@Blacklist", "Nivdal_FriendshipDeclineMembershipSuggestion", e.CommandArgument, false);
                    GND.ExecNivdalSQL("MessageId", "Nivdal_MarkInstantMessageActionDone", MessageIdHiddenField.Value);
                    Response.Redirect("~/Friends.aspx?Message=" + Answer);
                    break;
                case "JoinForum":
                    break;
            }
        }


        protected override void InitializeCulture()
        {

            OnlineUser ou = (OnlineUser)Session["User"];
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(ou.UICulture);
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ou.Culture);
        }
    }
}